﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using SharpDiary.Core.Controls;
using SharpDiary.Core.ORMapping;
using SharpDiary.Core.Data;
using SharpDiary.Core.Utility;

namespace SharpDiary.Reminder
{
    public partial class ReminderInfoListControl : ListControlBase
    {
        #region Fields & Properties



        #endregion

        #region Constructors

        public ReminderInfoListControl()
        {
            InitializeComponent();
        }

        #endregion

        #region Methods

        public override void ShowItems()
        {
            base.ShowItems();

            int summaryMaxTextLength = int.Parse(UserSettings.GetInstance().GetSettingValue("SummaryTextMaxLength", "20"));

            List<ReminderInfo> reminders = ReminderInfo.SelectAll<ReminderInfo>();
            foreach (ReminderInfo reminder in reminders)
            {
                ReminderInfoListItemControl item = new ReminderInfoListItemControl();
                item.SummaryTextMaxLength = summaryMaxTextLength;
                item.Reminder = reminder;

                AddItem(item);
            }
        }

        public override void ShowItems(string sql, params System.Data.Common.DbParameter[] parameters)
        {
            base.ShowItems(sql, parameters);

            int summaryMaxTextLength = int.Parse(UserSettings.GetInstance().GetSettingValue("SummaryTextMaxLength", "20"));

            if (string.IsNullOrEmpty(sql)) { ShowItems(); }
            else
            {
                List<ReminderInfo> reminders = DbObjectMappingHelper.QueryObjectList<ReminderInfo>(sql, parameters);
                foreach (ReminderInfo reminder in reminders)
                {
                    ReminderInfoListItemControl item = new ReminderInfoListItemControl();
                    item.SummaryTextMaxLength = summaryMaxTextLength;
                    item.Reminder = reminder;

                    AddItem(item);
                }
            }
        }

        #endregion
    }
}
